# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
   # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery # :secret => '205a07c04f580a8857f5f91cf7e27236'
  
 before_filter :initialize_user

  # make these available as ActionView helper methods.
  helper_method :logged_in? 

  protected

  # Check if the user is already logged in
  def logged_in? 
    @current_user.is_a?(User)
  end

  # setup user info on each page
  def initialize_user 
    @current_user = User.find_by_id(session[:user]) if session[:user]
  end
end